<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
	<script src="/layer/layer.js"></script>
	<style>
		#pwdLength span {
			display: none;
			float: left;
			height: 14px;
			width: 51px;
			font-size: 12px;
			text-align: center;
			line-height: 14px;
			color: white;
			border-right: 1px solid white;
		}
	</style>
</head>
<body>
<form class="form-inline definewidth m20" action="" method="get" id="myForm">
   <table>
		<tr>
			<td align="right">原密码:</td><td><input name="password" type="password"/></td>

		</tr>
		<tr>
			<td align="right">新密码:</td><td><input name="password1" type="password"/></td>
			<td  style="width: 75%">
				<div  id="pwdLength">
					<span style=" background-color:#999;">弱</span>
					<span style=" background-color:#666;">中</span>
					<span style=" background-color:#333;">强</span>
				</div>
				<div  id="pwdPrompt">
					密码可由字母、数字、特殊符号组成，长度为6-18个字符
				</div>
			</td>
		</tr>
		<tr>
			<td align="right">确认密码:</td><td><input name="password2" type="password"/></td>
		</tr>
		<tr>
			<td colspan="2" align="center"><br/>
				<input id="saveBtn" type="button" value="保存" class="btn btn-primary"/>
			</td>
		</tr>
   </table>
</form>
</body>
</html>
<script>
	$(function () {

		$("input[name='password1']").blur(function () {
			var pwd1 = $("input[name='password1']").val();
			check_pwd(pwd1);
		});
		$("#saveBtn").click(function () {
			var pwd = $("input[name='password']").val();
			var pwd1 = $("input[name='password1']").val();
			var pwd2 = $("input[name='password2']").val();
			if(pwd==null||pwd.length==0){
				layer.msg("请输入旧密码");
				return;
			}
			if(pwd1==null||pwd1.length==0){
				layer.msg("请输入新密码");
				return;
			}
			if(pwd2==null||pwd2.length==0){
				layer.msg("请再次输入新密码");
				return;
			}
			if(check_pwd(pwd1)){
				if(pwd1==pwd2){
					$.ajax({
						type: "POST",
						url: "/admin/pwd",
						data: $("#myForm").serialize(),
						dataType: "json",
						success: function (vo) {
							layer.msg(vo.msg)
							if(vo.code==200){
								top.window.location.href="/login.html";
							}
						}
					});
				}else{
					layer.msg("两次密码输入不一致");
				}
			}
		});
	});
	function check_pwd(pwd) {
		var reg1 = /(^\d{6,}$)|(^[a-zA-Z]{6,}$)|(^[^a-zA-Z0-9]{6,}$)/; //数字，字母或符号其中的一种
		var reg7 = /\d*\D*((\d+[a-zA-Z]+[^0-9a-zA-Z]+)|(\d+[^0-9a-zA-Z]+[a-zA-Z]+)|([a-zA-Z]+\d+[^0-9a-zA-Z]+)|([a-zA-Z]+[^0-9a-zA-Z]+\d+)|([^0-9a-zA-Z]+[a-zA-Z]+\d+)|([^0-9a-zA-Z]+\d+[a-zA-Z]+))\d*\D*/; //数字字母字符任意组合
		if (pwd.length < 6||pwd==null) {
			$("#pwdLength").css("display", "none");
			$("#pwdPrompt").css("display", "block");
			$("#pwdPrompt").html("密码长度不能小于6位");
			return false;
		} else {
			$("#pwdLength").css("display", "block");
			$("#pwdPrompt").css("display", "none");
			if (reg1.test(pwd)) {
				$("#pwdLength span:eq(0)").css("display", "block");
				$("#pwdLength span:eq(1)").css("display", "none");
				$("#pwdLength span:eq(2)").css("display", "none");
				return true;
			} else if (!reg7.test(pwd)) {
				$("#pwdLength span:eq(0)").css("display", "block");
				$("#pwdLength span:eq(1)").css("display", "block");
				$("#pwdLength span:eq(2)").css("display", "none");
				return true;
			} else {
				$("#pwdLength span:eq(0)").css("display", "block");
				$("#pwdLength span:eq(1)").css("display", "block");
				$("#pwdLength span:eq(2)").css("display", "block");
				return true;
			}
			return true;
		}
	}
</script>